(function (vc, vm) {
    vc.extends({
        data: {
            editShopCommunityInfo: {
                scId: '',
                communityId: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editShopCommunity', 'openEditShopCommunityModal', function (_params) {
                $that.refreshEditShopCommunityInfo();
                $('#editShopCommunityModel').modal('show');
                vc.copyObject(_params, $that.editShopCommunityInfo);
                $that.editShopCommunityInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods: {
            editShopCommunityValidate: function () {
                return vc.validate.validate({
                    editShopCommunityInfo: $that.editShopCommunityInfo
                }, {
                    'editShopCommunityInfo.communityId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "小区不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "小区错误"
                        },
                    ],
                    'editShopCommunityInfo.scId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "主键不能为空"
                        }
                    ]
                });
            },
            editShopCommunity: function () {
                if (!$that.editShopCommunityValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    'shopCommunity.updateShopCommunity',
                    JSON.stringify($that.editShopCommunityInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editShopCommunityModel').modal('hide');
                            vc.emit('shopCommunityManage', 'listShopCommunity', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditShopCommunityInfo: function () {
                $that.editShopCommunityInfo = {
                    scId: '',
                    communityId: ''
                }
            }
        }
    });
})(window.vc, window.vc.component);
